package com.learn.demo.controller;

import com.learn.demo.service.TestAsyncAndTransactionalService;
import com.learn.demo.service.TestAsyncService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * TestAsyncController
 *
 * @author banjiawei
 * @date 2022/01/10
 */
@RestController
@RequestMapping("/testAsync")
public class TestAsyncController {

    @Autowired
    private TestAsyncService testAsyncService;
    @Autowired
    private TestAsyncAndTransactionalService testAsyncAndTransactionalService;

    @GetMapping("/test")
    public String test(){
        testAsyncService.insertTestA();
        testAsyncService.insertTestB();
        return "OK";
    }

    @GetMapping("/list")
    public List<Object> list(){
        List<Object> list = new ArrayList<>();
        list.addAll(testAsyncService.listA());
        list.addAll(testAsyncService.listB());
        return list;
    }

    @GetMapping("/testAsyncAndTransactional")
    public String testAsyncAndTransactional(){
        testAsyncAndTransactionalService.testAsyncAndTransactional();
        return "OK";
    }
}
